import langData from '@/data/index'

function getLabelLangByChineseName(chineseName) {
  const item = langData.find(item => item.chineseName === chineseName)
  if (item) {
    return `:label="$t('erp.financial.${item.name}')"`
  } else {
    return `label="${chineseName}"`
  }
}

export default (config, noOperation, tableName = '') => {
  let tableColumn = config
    .map(({ name, chineseName, lang }) => {
      lang = lang ? lang : `erp.financial.${name}`
      const label = `:label="$t('${lang}')"`
      return `
            <!-- ${chineseName} -->
            <el-table-column prop="${name}" ${label} header-align="center"></el-table-column>
        `
    })
    .join(' ')
  let table = ''
  if (noOperation) {
    table = `
        <el-table :data="tableData" border style="margin-top: 20px;">
            <!--${tableName}-->
            <el-table-column ${getLabelLangByChineseName(tableName)}>
                <el-table-column type="selection" fixed width="40" header-align="center"></el-table-column>
                ${tableColumn}
            </el-table-column>
        </el-table>   
    `
  } else {
    table = `
        <el-table :data="tableData" border style="margin-top: 20px;" @row-dblclick="onEditClick">
            <!--${tableName}-->
            <el-table-column ${getLabelLangByChineseName(tableName)}>
                <el-table-column type="selection" fixed width="40" header-align="center"></el-table-column>
                <!--序号-->
                <el-table-column :label="$t('erp.common.table.index')" type="index" fixed width="50" align="center" />
                <!--操作-->
                <el-table-column :label="$t('erp.common.table.operation')" width="50" align="center">
                    <template slot-scope="scope">
                    <el-tooltip :content="$t('sys.user.table.modify')" class="item" effect="light" placement="top">
                        <el-button type="text" icon="el-icon-edit" @click="onEditClick(scope.row)"/>
                    </el-tooltip>
                    </template>
                </el-table-column>
                <!-- 附件 -->
                <el-table-column prop="bankId" :label="$t('erp.financial.enclosure')" width="50" header-align="center" align="center">
                    <template slot-scope="scope">
                    <!-- 上传附件 -->
                    <!-- <my-upload :relateCode="scope.row.pid" :fileProjectCode="'0008'" :upload-diag-list="uploadDiagList" @dialogClosed="pageReload"></my-upload> -->
                    </template>
                </el-table-column>
                ${tableColumn}
            </el-table-column>
        </el-table>   
    `
  }
  return table
}
